Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jul 30, 2025

This PR implements automatic live VOD switching when stream discontinuities are detected, addressing playback issues during ad breaks and stream quality problems. The implementation follows the approach used in TwitchLink for handling discontinuous streams.

Key Features

Smart Discontinuity Handling: The system now monitors discontinuities across playlist refresh cycles (not just individual segments) and automatically switches between live HLS and VOD-style playlists to maintain smooth playback.

Configurable Thresholds:

  • Switches to VOD playlist after 3 consecutive cycles with discontinuities
  • Returns to original playlist after 5 consecutive clean cycles
  • Thresholds are easily configurable via constants

Seamless Integration: Built on top of the existing TX-Queue IPC streaming architecture and TSDuck HLS discontinuity detection, requiring minimal changes to the codebase.

Implementation Details

Extended Twitch API (twitch_api.h/cpp)

  • Added GenerateVodPlaylistUrl() function that creates VOD-style URLs when discontinuities persist
  • Uses same HLS endpoint but with stabilizing parameters (fast_bread=false, cache busting, etc.)

Enhanced TX-Queue Stream Manager (tx_queue_ipc.h/cpp)

  • Added persistent discontinuity state tracking across playlist refreshes
  • Implemented dynamic playlist URL switching in the producer thread
  • Added comprehensive logging for monitoring and debugging

Core Logic Flow

// Example of the switching logic
if (discontinuities_detected) {
    discontinuity_count++;
    if (discontinuity_count >= 3 && !using_vod_playlist) {
        switch_to_vod_playlist();  // More stable playback
    }
} else {
    clean_cycles++;
    if (clean_cycles >= 5 && using_vod_playlist) {
        switch_to_original_playlist();  // Resume normal streaming
    }
}

Debug Output

The feature provides clear logging to monitor its operation:

[PRODUCER] Discontinuities detected in playlist - buffer flushing enabled
[LIVE-VOD] Discontinuity threshold reached (3/3), switching to VOD playlist
[LIVE-VOD] Switched to VOD playlist: https://usher.ttvnw.net/...
[LIVE-VOD] Clean playback restored (5/5), switching back to original playlist

Testing

  • Unit tested the switching logic to verify correct threshold behavior
  • Verified integration with existing TX-Queue streaming architecture
  • Added comprehensive test procedures to TESTING_GUIDE.md

This implementation provides a robust solution for handling stream discontinuities while maintaining compatibility with all existing functionality and streaming modes.

Fixes #137.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot AI changed the title [WIP] Use live VOD when discontinuities are found Implement live VOD switching when discontinuities are detected Jul 30, 2025
Copilot AI requested a review from Zero3K July 30, 2025 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use live VOD when discontinuities are found

2 participants